/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * This file is part of retabel.
 *
 * Copyright (c) 2011 by individual contributors as indicated by the
 * @author tags. See the copyright.txt file in the distribution
 * for a full listing of individual contributors.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.retabel.jsf;

import org.apache.commons.lang.StringUtils;

import java.net.URI;
import java.net.URISyntaxException;

/**
 * Rendered document uri builder
 * <p/>
 * <h3>Extra-Info</h3>
 * Created: 20:39 08.09.11
 *
 * @author Peter Herber
 * @version 1.0
 */
public class RenderedDocumentUriBuilder extends WebUriBuilder {

    private static final String WEB_SERVICE_RENDER_PATH = "/rendereddocuments/";

    public static URI getRenderedDocumentsXmlSchemaURI() throws URISyntaxException {
        return fromPath(WEB_XMLSCHEMA_PATH).resolve(new URI("renderedDocuments.xsd"));
    }

    public static URI getRenderedDocumentsURI(int first, int maxRows) throws URISyntaxException {
        URI uri = fromPath(WEB_SERVICE_RENDER_PATH);

        StringBuilder sb = new StringBuilder();
        sb.append("?first=" + first);
        sb.append("&maxRows=" + maxRows);

        return uri.resolve(new URI(sb.toString()));
    }

    public static URI getRenderedDocumentPartURI(String documentIdentifier, int renderedDocumentPartId) throws URISyntaxException {
        return fromPath(WEB_SERVICE_RENDER_PATH).resolve(new URI(StringUtils.join(
            new Object[]{documentIdentifier, "/", new Integer(renderedDocumentPartId)})));
    }

    public static URI getRenderedDocumentDeleteURI(String documentIdentifier) throws URISyntaxException {
        return fromPath(WEB_SERVICE_RENDER_PATH).resolve(new URI(StringUtils.join(
            new Object[]{documentIdentifier})));
    }
}
